<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>    

<head>
	<style type="text/css">
		.e-input{
			border:1px solid #ccc;
			width:300px;
		}
	</style>
	<script type="text/javascript" src="<c:url value='/easyui/datagrid-detailview.js'/>"></script>
	<script type="text/javascript" src="<c:url value='/js/base64.js'/>"></script>
	<SCRIPT language=JAVASCRIPT src='<c:url value="/ckeditor/ckeditor.js"/>'></SCRIPT>
	<script type="text/javascript">
		$(function(){
			init();
		});
		function init(){
			$('#dlg').dialog({
				onOpen:function(){
					CKEDITOR.replace( 'content' ,{
		skin : 'office2003',   //'kama', 'v2', 'office2003'
		height : 480,
		width : 800
	});
				},
				onClose:function(){
					var instance = CKEDITOR.instances['content'];
				    if(instance)
				    {
				        CKEDITOR.remove(instance);
				    }

				}
			});
			
			$('#t-types').tree({
				onClick:function(node){
					$('#t-infos').datagrid('reload', {privilegeTypeId:node.id});
				}
			});
			$('#t-infos').datagrid({
				loadMsg:'',				
				view:detailview,
				detailFormatter:function(index,row){
				  var content = '';
				  if (row.title)  {
					   content += '<span style="color:blue;font-weight:700">标题：</span></br>';
					   content += '<div style="padding:5px">'+ row.title.replace(/\r\n/gi,'<br/>')+'</div>';
					}
					if (row.infofrom)  {
					   content += '<span style="color:blue;font-weight:700">来源：</span></br>';
					   content += '<div style="padding:5px">'+ row.infofrom.replace(/\r\n/gi,'<br/>')+'</div>';
					}
					
if (row.content)  {
	var b = new Base64();  
	   content += '<span style="color:blue;font-weight:700">资讯内容：</span></br>';
	   content += '<div style="padding:5px">'+ b.decode(row.content)+'</div>';
	}
           
					return '<div style="padding:5px">' + content + '</div>';
				}
				
			});
			
		}
		
		function formatType(value, row){
			if (row.infotype) return row.infotype.name;
			return "未分类";
		}

		var actionUrl;
		function newItem(){
			$('#dlg').dialog('setTitle', '新增资讯').dialog('open');
			$('#myform').form('clear');
			actionUrl = '<c:url value="/portal/info/save"/>';
		}
		function editItem(){
			var t = $('#t-infos');
			var row = t.datagrid('getSelected');
			if (row){
				$('#myform').form('load', row);
				var b = new Base64();  
				$('#content').val(b.decode(row.content));
				$('#dlg').dialog('setTitle', '修改资讯').dialog('open');
				
				actionUrl = '<c:url value="/portal/info/update"/>?id=' + row.id;
			}
		}
		function deleteItem(){
			var t = $('#t-infos');
			var node = t.datagrid('getSelected');
			if (node){
				$.messager.confirm('删除确认', '是否确定要删除选择资讯?', function(r){
					if (r){
				$.ajax({
					url:'<c:url value="/portal/info/destroy"/>?id=' + node.id,
					type:'post',
					success:function(){	
						$('#t-infos').datagrid('reload');
					}
				});
					}});
			}
		}
		function saveItem(){
			$('#myform').form('submit', {
				url:actionUrl,
				onSubmit:function(){
					return $('#myform').form('validate');
				},
				success:function(data){
					$('#dlg').dialog('close');
					$('#t-infos').datagrid('reload');
				}
			});
		}
		
		function formatstatus(value){
			if (value == "1") 
				return "正式";
			else
				return "草稿";
		}
		
		function formattotop(value){
			if (value == "1") 
				return "<font color=red>置顶</font>";
			if (value == "0") 
				return "<font color=blue>不置顶</font>";

			}
		
		function move(dir){
			var row = $('#t-infos').datagrid('getSelected');
			$.getJSON('<c:url value="/portal/info/move"/>', {id:row.id,dir:dir}, function(){
				$('#t-infos').datagrid('reload');
			});
		}
	</script>
</head>
<body>
	<div class="easyui-layout" fit="true">
		<div region="north" border="false" style="height:40px;padding:5px;overflow:hidden;"  >
			<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newItem()">新增资讯</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editItem()">修改资讯</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deleteItem()">删除资讯</a>
		</div>
		<div region="west" border="true" style="border-right:1px solid #e3e9ff;width:150px;">
			<div style="background:#fafafa;padding-left:5px;">
				资讯分类
				<a href="<c:url value='/portal/infoType/index'/>?mmid=${mm.id}" class="easyui-linkbutton" iconCls="icon-edit" plain="true"></a>
			</div>
			<div style="padding:5px;">
				<ul id="t-types" url="<c:url value='/portal/infoType/getTypes'/>"></ul>
			</div>
		</div>
		<div region="center" border="true">
			<table id="t-infos" style="display: none;"
					url="<c:url value='/portal/info/getInfos'/>"
					singleSelect="true" rownumbers="true"
					idField="id" pagination="true"
					border="false" fit="true" fitColumns="true">
				<thead>
					<tr>
						<th field="infotypeid" width="80" sortable="false" formatter="formatType">资讯类型</th>
<th field="title" width="150" sortable="false">标题</th>
<th field="infofrom" width="100" sortable="false">来源</th>
<th field="editdate" width="100" sortable="false">编辑时间</th>
<th field="totop" width="80" sortable="false" formatter="formattotop">置顶</th>
<th field="passflag" width="80" sortable="false" formatter="formatstatus">状态</th>
<th field="hot" width="80" sortable="false">点击率</th>
<th field="oper" width="80" sortable="false">操作人员</th>
					</tr>
				</thead>
			</table>
		</div>
	</div>
	
	<div id="dlg" maximized="true" class="easyui-dialog" closed="true" modal="true" style="padding:10px;">
		<form id="myform" method="post">
			<table>
					<tr>
<td style="width:80px">资讯类型</td>
<td colspan="3">
<input type="text" id="infotypeid" name="infotypeid" class="easyui-combotree"
								url="<c:url value='/portal/infoType/getTypes'/>"
								required="true">
</td>
</tr>	


<tr>
<td style="width:80px">标题</td>
<td colspan="3"><input type="text" class="easyui-validatebox e-input" id="title" name="title" style="width:590px;" data-options="required:true,editable:true" ></input></td>
</tr>	
<tr>
<td style="width:80px">来源</td>
<td colspan="3"><input type="text" class="easyui-validatebox e-input" id="infofrom" name="infofrom" style="width:590px;" data-options="required:false,editable:true" ></input></td>
</tr>
<tr>
<td style="width:80px">状态</td>
<td >
<select id="passflag" name="passflag" 
	data-options="required:true,editable:true" panelHeight="auto" class="easyui-combobox" style="width:250px;">
		<option value="-1">草稿</option>
		<option value="1">正式</option>		
</select></td>
<td style="width:80px" align="center">置顶</td>
<td>
<select id="totop" name="totop" 
	data-options="required:true,editable:true" panelHeight="auto" class="easyui-combobox" style="width:250px;">
		<option value="0">不置顶</option>	
		<option value="1">置顶</option>		
</select></td>
</tr>	
<tr>
<td style="width:80px" >资讯内容</td>
<td colspan="3">
<textarea type="text" class="easyui-validatebox e-input" id="content" name="content" style="width:590px;height:350px" data-options="required:false,editable:true" ></textarea>

</td>
</tr>	
	
			</table>
		</form>
		<div style="margin-top:10px;text-align:center;">
			<a href="#" class="easyui-linkbutton" iconCls="icon-save" onclick="saveItem()">保存</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
		</div>
	</div>
	
	
</body>
